package com.mxx.democharts2.web.controller;

import com.github.pagehelper.PageInfo;
import com.mxx.democharts2.dto.PageDto;
import com.mxx.democharts2.dto.YuancheDto;
import com.mxx.democharts2.service.YuancheService;
import com.mxx.democharts2.support.RestResponse;
import com.mxx.democharts2.utils.PageQuery;
import com.mxx.democharts2.vo.YuancheQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/yuanche")
public class YuancheController {

    @Autowired
    private YuancheService yuancheService;

    @GetMapping("/list")
    public RestResponse list(Integer page, Integer limit, YuancheQuery yuancheQuery){

        // TODO 输入校验


        // 封装查询条件
        PageQuery<YuancheQuery> yuanchePageQuery = new PageQuery<>();
        yuanchePageQuery.setPage(page);
        yuanchePageQuery.setLimit(limit);

        yuanchePageQuery.setQueryItem(yuancheQuery);

        // 查询
        PageInfo<YuancheDto> pageInfo = yuancheService.getYuancheList(yuanchePageQuery);



        PageDto<YuancheDto> data = new PageDto<>(pageInfo.getTotal(), pageInfo.getList());
        return new RestResponse(data);
    }

    @GetMapping("/test")
    public String test(){
        System.out.println("123---");
        return "123";
    }
}
